#!/bin/bash
# Author    : MoShangSan
# create_ts : 2022-12-28
# program   : Compile Code, Convert DOS/Mac text file format into Unix, Tar package
bash_path=$(cd `dirname $0`; pwd)
CURRENT_PATH=$(cd ${bash_path}/..; pwd)
CURRENT_TIME=$(date "+%Y%m%d_%H%M")
SHELL_DIR_PATH="/data/code/Shell"
LOG_FILE=${CURRENT_PATH}/log/$(date "+%Y%m%d%H%M%S").log

SOURCE_DIR=$1
CODECHECK_DIR=$2

function LOG() {
    USER=$(whoami) ####那个用户在操作
    if [ ! -e ${CURRENT_PATH}/log ];then
       mkdir ${CURRENT_PATH}/log
    fi
    if [ ! -f ${LOG_FILE} ];then
       touch ${LOG_FILE}
    fi
    echo "[${DATE}] ${USER} [$1] $2"
    echo "[${DATE}] ${USER} [$1] $2" >> ${LOG_FILE}  ######（$0脚本本身，$@将参数作为整体传输调用, >> 将输出结果以追加的方式添加重定向到本地文件中）
}

LOG INFO "--start package.sh---------"

# 代码检查
bash ${CURRENT_PATH}/script/build.sh $1 $2 $3
LOG INFO "CodeCheck Finish"

# 代码程序打包
cd ${CODECHECK_DIR}
tar -zcvf automatic_tool_${CURRENT_TIME}.tar.gz ${CURRENT_PATH}/src
LOG INFO "Tar package Finish"

# 机器人消息通知
if [ $IS_PUSH_CHAT == "TRUE" ];then
   bash $SHELL_INSTALL_PATH/chat_robot.sh "Automatic_Tool" "[JENKINS]Build and_Package_Success" "url:http://buzhoushan.local:8080/job/automatic_tool/"
fi